package br.inatel.ec203.projeto.view;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

public class UserDataPanel extends JPanel{

	private static final long serialVersionUID = 3486918794634459049L;
	
	private JLabel userNameLabel;
	private JLabel passWordLabel;
	private JTextField userNameTextField;
	private JPasswordField passWordTextField;
	
	public UserDataPanel() {
		super();
		
		initialize();		
	}

	private void initialize() {
		
		setLayout(createGridLayout());
		
		add(getUserNameLabel());
		add(getUserNameTextField());
		add(getPassWordLabel());
		add(getPassWordField());
		
		setBorder(createBorder());
		
	}

	private Border createBorder() {
		
		EmptyBorder innerBorder = new EmptyBorder(5, 5, 5, 5);
		TitledBorder titleBorder = new TitledBorder("Dados do Usuario");
		EmptyBorder outerBorder = new EmptyBorder(5, 5, 5, 5);
		CompoundBorder innerCompoundBorder = new CompoundBorder(innerBorder, titleBorder);
		CompoundBorder totalBorder = new CompoundBorder(innerCompoundBorder, outerBorder);
		return totalBorder;
	}

	private GridLayout createGridLayout() {
		GridLayout gridLayout = new GridLayout();
		
		gridLayout.setRows(2);
		gridLayout.setColumns(2);
		gridLayout.setHgap(5);
		gridLayout.setVgap(5);
		
		return gridLayout;
	}

	private JLabel getUserNameLabel() {
		if (userNameLabel == null) {
			userNameLabel = new JLabel();
			userNameLabel.setText("Nome do usuario");			
		}
		return userNameLabel;
	}

	private JLabel getPassWordLabel() {
		if (passWordLabel == null) {
			passWordLabel = new JLabel();
			passWordLabel.setText("Senha do Usuario");			
		}
		return passWordLabel;
	}

	private JTextField getUserNameTextField() {
		if (userNameTextField == null) {
			userNameTextField = new JTextField();
		}
		return userNameTextField;
	}

	private JPasswordField getPassWordField() {
		if (passWordTextField == null) {
			passWordTextField = new JPasswordField();
		}
		return passWordTextField;
	}	
	
	public String getUserName() {
		return getUserNameTextField().getText();
	}
	
	public String getPassWord() {
		char[] passWord;
		passWord = getPassWordField().getPassword();
		return new String(passWord);
	}
}








